<?php
/**
 * Created by PhpStorm.
 * User: junyv
 * Date: 2016/9/22
 * Time: 16:32
 */
namespace app\manage\controller;
class Cache extends Base
{
    public function cacheAll() {
        $model = [
            ['controller' => 'Setting','action' => 'doCache','name'=>'更新站点设置缓存'],
            ['controller' => 'Nav','action' => 'doCache','name'=>'更新导航缓存'],
            ['controller' => 'AskCate','action' => 'doCache' ,'name'=>'更新问答分类缓存'],
            ['controller' => 'ArticleCate','action' => 'doCache' ,'name'=>'更新文章分类缓存'],
            ['controller' => 'ActivityCate','action' => 'doCache' ,'name'=>'更新活动分类缓存'],
            ['controller' => 'OneCate','action' => 'doCache' ,'name'=>'更新单页分类缓存'],
            ['controller' => 'City','action' => 'doCache' ,'name'=>'更新城市缓存'],
            ['controller' => 'Linkmenu','action' => 'doCache' ,'name'=>'更新联动菜单缓存'],
            ['controller' => 'Keyword','action' => 'doCache' ,'name'=>'更新关联链接缓存'],
            ['controller' => 'Badword','action' => 'doCache' ,'name'=>'更新敏感词缓存'],
            ['controller' => 'Badip','action' => 'doCache' ,'name'=>'更新禁止IP缓存'],
        ];
        if(input('param.sub')){
            $p = input('param.page/d',0);
            if(array_key_exists($p,$model)){
                $m = $model[$p];
                $flag = action($m['controller'].'/'.$m['action']);
                if($flag){
                    $str = $m['name'].'成功....';
                }else{
                    $str = $m['name'].'<span style="color:#ff0000">失败....</span>';
                }
                $status = 1;
            }else{
                $str = '<span style="color:#ff0000">更新全站缓存完成....</span>';
                $status = 0;
            }
            $this->ajaxReturn($status,$str,$p+1);
        }else{
            $this->assign('model',json_encode($model));
            return $this->fetch('index/cacheall');
        }

    }
}